package ptij.vocoder.baseModel.closed_loop;

import ptolemy.actor.*;
import ptolemy.kernel.*;
import ptolemy.kernel.util.*;
import ptolemy.data.ObjectToken;
import ptolemy.data.Token;
import ptolemy.data.type.*;

import ptij.vocoder.baseModel.*;

//////////////////////////////////////////////////////////////////////////
//// PitchFr6
/**
@author Ivan Jeukens
@version v 0.1 07/08/2003
*/
public class PitchFr6 extends TypedAtomicActor {

    public PitchFr6(CompositeEntity container, String name) throws
            IllegalActionException, NameDuplicationException {
        super(container, name);

        exc = new TypedIOPort(this, "exc", true, false);
        exc.setTypeEquals(BaseType.OBJECT);

        xn = new TypedIOPort(this, "xn", true, false);
        xn.setTypeEquals(BaseType.OBJECT);

        h = new TypedIOPort(this, "h", true, false);
        h.setTypeEquals(BaseType.OBJECT);

        t0_min = new TypedIOPort(this, "t0_min", true, false);
        t0_min.setTypeEquals(BaseType.OBJECT);

        t0_max = new TypedIOPort(this, "t0_max", true, false);
        t0_max.setTypeEquals(BaseType.OBJECT);

        pit_frac = new TypedIOPort(this, "pit_frac", false, true);
        pit_frac.setTypeEquals(BaseType.OBJECT);

        lag = new TypedIOPort(this, "lag", false, true);
        lag.setTypeEquals(BaseType.OBJECT);

        txdtx_ctrl = new TypedIOPort(this, "txdtx_ctrl", true, false);
        txdtx_ctrl.setTypeEquals(BaseType.OBJECT);
    }

    ///////////////////////////////////////////////////////////////////
    ////                     ports and parameters                  ////

    // Input ports
    public TypedIOPort exc;
    public TypedIOPort xn;
    public TypedIOPort h;
    public TypedIOPort t0_min;
    public TypedIOPort t0_max;
    public TypedIOPort txdtx_ctrl;

    // Output Ports
    public TypedIOPort pit_frac;
    public TypedIOPort lag;

    ///////////////////////////////////////////////////////////////////
    ////                         public methods                    ////

    public void initialize() throws IllegalActionException {
        super.initialize();
    }

    public void fire() throws IllegalActionException {
        ObjectToken obj = (ObjectToken) txdtx_ctrl.get(0);
        Short txdtx = (Short) obj.getValue();

        if((txdtx.shortValue() & Cnst.TX_SP_FLAG) != 0) {
            obj = (ObjectToken) exc.get(0);
            Short [] arg1 = (Short []) obj.getValue();

            obj = (ObjectToken) xn.get(0);
            Short [] arg2 = (Short []) obj.getValue();

            obj = (ObjectToken) h.get(0);
            Short [] arg3 = (Short []) obj.getValue();

            obj = (ObjectToken) t0_min.get(0);
            Short arg4 = (Short) obj.getValue();

            obj = (ObjectToken) t0_max.get(0);
            Short arg5 = (Short) obj.getValue();

            _pitch_fr6(arg1, arg2, arg3, arg4, arg5);

            lag.broadcast(new ObjectToken(_l));
            pit_frac.broadcast(new ObjectToken(_frac));
        }
    }

    ///////////////////////////////////////////////////////////////////
    ////                         private methods                   ////

    private void _pitch_fr6(Short [] exc, Short [] xn, Short [] h, 
            Short t0_min, Short t0_max) {

    }

    ///////////////////////////////////////////////////////////////////
    ////                         private variables                 ////

    private Short _frac;
    private Short _l;
}
